<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    :cancelText="$t('取消')"
    :okText="$t('保存')">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="22">
            <a-form-model-item :label="$t('物流公司')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logisticsCompany">
              <a-input v-model="model.logisticsCompany" :maxLength="32" :placeholder="$t('请输入物流公司')"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="22">
            <a-form-model-item :label="$t('物流单号')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="logisticsNo">
              <a-input v-model="model.logisticsNo" :maxLength="32" :placeholder="$t('请输入物流单号')"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage'
  export default {
    name: 'LogisticsModal',
    components: {},
    data(){
      return {
        title:this.$t('物流信息'),
        width: 800,
        visible: false,
        confirmLoading:false,
        model:{},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        validatorRules: {
          logisticsCompany: [
            { required: true, message: this.$t('请输入物流公司')},
          ],
          logisticsNo: [
            { required: true, message: this.$t('请输入物流单号')},
          ]
        },
        url: {
          edit: "/gift/order",
        }
      }
    },
    methods:{
      show(record){
        let that=this
        that.visible=true
        that.model=Object.assign({},record)
      },
      handleOk () {
        let that=this
        that.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!that.model.id){
              httpurl+=that.url.add;
              method = 'post';
            }else{
              httpurl+=that.url.edit;
              method = 'put';
            }
            let query={
              id:that.model.id,
              logisticsNo:that.model.logisticsNo,
              logisticsCompany:that.model.logisticsCompany
            }
            httpAction(httpurl,query,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.visible=false
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>